<template>
  <div>
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>您正在做的业务是:</el-breadcrumb-item>
        <el-breadcrumb-item>生产设计</el-breadcrumb-item>
        <el-breadcrumb-item>产品物料组成设计</el-breadcrumb-item>
        <el-breadcrumb-item>物料组成设计单审核</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!--审核  -->
    <div>
      <el-table
          :data="moduleData"
          border
          style="width: 100%">
        <el-table-column
            fixed
            prop="designId"
            label="设计编号"
            width="150">
        </el-table-column>
        <el-table-column
            prop="productId"
            label="产品编号"
            width="120">
        </el-table-column>
        <el-table-column
            prop="productName"
            label="产品名称"
            width="120">
        </el-table-column>
        <el-table-column
            prop="register"
            label="登记人"
            width="120">
        </el-table-column>
        <el-table-column
            prop="createTime"
            label="登记时间"
            width="240">
        </el-table-column>
        <el-table-column
            prop="costPriceSum"
            label="物料总成本"
            width="120">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row,'S001-1','是否同意审核')" type="text" size="medium">同意</el-button>
            <el-button @click="handleClick(scope.row,'S001-2','确定拒绝审核吗')" type="text" size="medium">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--   分页 -->
    <!--分页    -->
    <div class="block">
      <el-pagination
          @size-change="handleSizeChange"
          :current-page="Number(pageNum)"
          :page-sizes="[2, 4, 8, 16]"
          :page-size="Number(pageSize)"
          @current-change="handleCurrentChange"
          layout="total, sizes, prev, pager, next, jumper"
          :total="Number(total)">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import request from "../../request.js"

export default {
  name: "ModuleCheck",
  data() {
    return {
      moduleData: [],
      pageNum: '',
      pageSize: '',
      total: '',
    }
  },
  methods: {
    handleClick(row, tag, message) {

      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.post("http://localhost:8150/module/checkModule", {
          'checkTag': tag,
          'productId': row.productId,
          'id': row.id
        }).then(data => {
          if (data.data.flag==false) {
            this.$message({
              showClose: true,
              message: data.data.message,
              type: data.data.flag == true ? "success" : "error"
            })
            return;
          }
          this.init();
          this.$message({
            showClose: true,
            message: data.data.message,
            type: data.data.flag == true ? 'success' : 'error'
          });
        }).catch(e => {
          alert("错误信息为:" + e)
        })
        console.log(row);
        /*       this.$message({
                 type: 'success',
                 message: '删除成功!'
               });*/
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },

    /**
     * 初始化
     */
    init() {
      axios.get("http://localhost:8150/module/queryModule", {
        params: {
          'checkTag': 'S001-0',
          'pageNum': this.pageNum,
          'pageSize': this.pageSize
        }
      }).then(data => {
        if (data.data.flag==false) {
          this.$message({
            showClose: true,
            message: data.data.message,
            type: data.data.flag == true ? "success" : "error"
          })
          return;
        }
        this.moduleData = data.data.data.records;
        this.pageNum = data.data.data.current;
        this.pageSize = data.data.data.size;
        this.total = data.data.data.total;
      })
    },
    handleSizeChange(val) {
      this.pageSize = val;
      console.log(`每页 ${val} 条`);
      this.init();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      console.log(`当前页: ${val}`);
      this.init();
    },
  }, created() {
    this.init();
  }
}
</script>

<style scoped>

</style>